package com.jaya.budan.thirdpush;

import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jaya.budan.R;
import com.tencent.qcloud.tim.uikit.modules.chat.layout.message.holder.ICustomMessageViewGroup;
import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationLayout;
import com.tencent.qcloud.tim.uikit.modules.conversation.ConversationListLayout;
import com.tencent.qcloud.tim.uikit.modules.conversation.base.ConversationInfo;
import com.tencent.qcloud.tim.uikit.modules.message.MessageInfo;

import java.util.ArrayList;
import java.util.List;

public class ConversationLayoutHelper {

    public static void customizeConversation(final ConversationLayout layout) {

        ConversationListLayout listLayout = layout.getConversationList();

        listLayout.setItemTopTextSize(16); // 设置adapter item中top文字大小
        listLayout.setItemBottomTextSize(12);// 设置adapter item中bottom文字大小
        listLayout.setItemDateTextSize(10);// 设置adapter item中timeline文字大小
        listLayout.setItemAvatarRadius(5);// 设置adapter item头像圆角大小
        listLayout.disableItemUnreadDot(true);// 设置adapter item是否不显示未读红点，默认显示

        // 动态插入，删除Item，包括自定义会话
        final ConversationInfo customInfo = new ConversationInfo();
        customInfo.setType(ConversationInfo.TYPE_CUSTOM);
        customInfo.setId("自定义会话");
        customInfo.setGroup(false);
        customInfo.setTitle("乔丹风行8代跑鞋 风随我动！");
        customInfo.setLastMessage(new MessageInfo());
        List url_list = new ArrayList();
        url_list.add("https://img1.gtimg.com/ninja/2/2019/03/ninja155375585738456.jpg");
//        customInfo.setIconUrlList(url_list);
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                layout.addConversationInfo(0, customInfo);
            }
        }, 3000);

        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                layout.removeConversationInfo(0);
            }
        }, 5000);
    }

//    private void buildVoiceCallView(ICustomMessageViewGroup parent, MessageInfo info, TRTCAudioCallImpl.CallModel data) {
//        if (data.action == TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_DIALING) {
//            // 把自定义消息view添加到TUIKit内部的父容器里
//            View view = LayoutInflater.from(AndroidApplication.getInstance()).inflate(R.layout.dial_senc_call_message, null, false);
//            parent.addMessageItemView(view);
//            TextView tv = view.findViewById(R.id.tv_content);
//            if (info.isSelf()) {
//                tv.setText("您发起了语音通话");
//            } else {
//                tv.setText("对方发起了语音通话");
//            }
//            return;
//        }
//
//        // 把自定义消息view添加到TUIKit内部的父容器里
//        View view = LayoutInflater.from(AndroidApplication.getInstance()).inflate(R.layout.dial_custom_message, null, false);
//        parent.addMessageContentView(view);
//
//        // 自定义消息view的实现，这里仅仅展示文本信息，并且实现超链接跳转
//        TextView textView = view.findViewById(R.id.tv_dial_status);
//
//        ImageView ivLeft = view.findViewById(R.id.iv_left);
//        ImageView ivRight = view.findViewById(R.id.iv_right);
//        if (info.isSelf()) {
//            ivRight.setVisibility(View.VISIBLE);
//            ivLeft.setVisibility(View.GONE);
//            textView.setTextColor(getResources().getColor(R.color.white));
//        } else {
//            ivRight.setVisibility(View.GONE);
//            ivLeft.setVisibility(View.VISIBLE);
//            textView.setTextColor(getResources().getColor(R.color.color_333333));
//        }
//        String text;
//        switch (data.action) {
//            case TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_SPONSOR_CANCEL:
//                text = "已取消";
//                break;
//            case TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_REJECT:
//                text = "已拒绝";
//                break;
//            case TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_SPONSOR_TIMEOUT:
//                text = "无人接听";
//                break;
//            case TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_HANGUP:
//                if (data.duration == 0) {
//                    text = "通话结束";
//                } else {
//                    text = "通话结束 " + TimeUtils.millis2StringByCorrect(data.duration * 1000, data.duration >= 60 * 60 ? "HH:mm:ss" : "mm:ss");
//                }
//                break;
//            case TRTCAudioCallImpl.CallModel.VIDEO_CALL_ACTION_LINE_BUSY:
//                text = "忙线中";
//                break;
//            default:
//                text = "未知通话错误";
//                break;
//        }
//        textView.setText(text);
//    }
}
